/*
 * Created on 2006-8-16
 */
package spatial.geometry;

import java.awt.geom.Point2D;

/**
 * A location made of x and y coordinate values. <br>
 * Note that this is an immutable class, so it does not need a clone() method
 * and it can be shared safely.
 * 
 * @author wu wei
 * @email wuw@nus.edu.sg
 */
final public class Location extends Point2D.Double {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3543753098423549125L;

	public Location(double x, double y) {
		super(x, y);
	}
	
	public Location(Point2D.Double p){
		this(p.x, p.y);
	}

	public double distance(Location anotherPoint) {
		double deltaX = this.x - anotherPoint.x;
		double deltaY = this.y - anotherPoint.y;
		return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
	}

	public double xDistance(Location anotherPoint) {
		return this.x - anotherPoint.x;
	}

	public double yDistance(Location anotherPoint) {
		return this.y - anotherPoint.y;
	}

	public String toParenthesisString() {
		String s = "(" + this.x + "," + this.y + ")";
		return s;
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	// private static double epsilon = 0.0000001;

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		return super.equals(obj);
		// if (obj instanceof Location) {
		// Location al = (Location) obj;
		// // if ((this.x -al.x)<epsilon && (this.y - al.y)<epsilon) {
		// // return true;
		// // }
		// if(this.x==al.x && this.y==al.y){
		// return true;
		// }
		// }
		// return false;
	}

	public String toString() {
		String s;
		String seperator = "\t";
		s = this.x + seperator + this.y;
		// s=s+"\t"+this.hashCode();
		return s;
	}

	@Override
	public int hashCode() {
		// return (int)this.x*11+ (int)this.y*7;
		return super.hashCode();
	}

}
